<?php 

	/***********************************\
	*									*
	*	Management of Google Code CSV.	*
	*									*
	\***********************************/

	//Stores CSV file to an array and cleans the separators and quotes.
	function arrayCSV()
	{
		$CSVText = file_get_contents(CSV_PATH);

		$CSVText = str_replace("\"", "", $CSVText);
    	$CSVTextMod = str_replace("\n", ROW_SEPARATOR, $CSVText);

    	$data = explode(ROW_SEPARATOR, $CSVTextMod);

		return $data;
	}

	//Return true if the row contains the constant DONE
	function rowContains($row)
	{
		if(stristr($row, DONE) != null)
			return true;
		else
			return false;
	}

	//Manage a array with the correct rows (Status Done and Done-TODO)
	function CSVCleaner($data, $dataMod)
	{
		for($i = 0; $i < count($data); $i++)
		{
			if(rowContains($data[$i]))
			{
				$dataMod[] = $data[$i];
			}
		}

		return $dataMod;
	}

	//Return the array $dataStruct who contains data chosen and processed
	function dataManagement($dataMod, $dataFinal)
	{
		for($i = 0; $i < count($dataMod); $i++)
		{
			$dataTemp = explode(CSV_SEPARATOR, $dataMod[$i]);

			for($j = 0; $j < count($dataTemp); $j++)
			{	
				if($j == 3)
				{
					$dataFinal[] = $dataTemp[$j] . $dataTemp[$j+1];
				}
				if($j != 3 && $j != 4)
				{
					$dataFinal[] = $dataTemp[$j];
				}
			}
		}

		for($k = 1; $k <= count($dataFinal); $k++)
		{
			if($k%7==0)
			{
				$dataStruct[] = array("ID"=>$dataFinal[$k-7], "Status"=>$dataFinal[$k-6], "Owner"=>$dataFinal[$k-5], "Closed"=>$dataFinal[$k-4], "Timestamp"=>$dataFinal[$k-3], "Score"=>$dataFinal[$k-2], "Cc"=>$dataFinal[$k-1]);
			}			
		}

		return $dataStruct;
	}

?>